#!/usr/bin/env python
"""
重置AI评估状态
"""
import os
import sys
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inter_api.settings')
django.setup()

from django.contrib.auth import get_user_model
from students.models import Student
from resume_management.models import Resume

User = get_user_model()

def reset_ai_evaluation_status():
    """重置AI评估状态"""
    print("重置AI评估状态...")
    
    try:
        # 获取测试用户和简历
        user = User.objects.get(username='test_student')
        student = Student.objects.get(user=user)
        resume = Resume.objects.filter(student=student).first()
        
        if not resume:
            print("没有找到测试简历")
            return
            
        print(f"找到简历: ID={resume.id}, 当前AI评估状态: {resume.ai_evaluation_status}")
        
        # 重置AI评估状态
        resume.ai_evaluation_status = 'not_started'
        resume.ai_evaluation_error = None
        resume.ai_evaluation_file = None
        resume.ai_evaluation_file_url = None
        resume.ai_evaluation_job_position = None
        resume.ai_evaluation_at = None
        resume.save()
        
        print(f"✅ 已重置简历AI评估状态")
        print(f"新状态: {resume.ai_evaluation_status}")
        
    except Exception as e:
        print(f"重置失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    reset_ai_evaluation_status()
